package com.lovvyang.dao.impl;

import com.lovvyang.dao.UserDao;
import com.lovvyang.domain.User;
import com.lovvyang.util.JDBCUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author lovvyang
 * @date 2020/6/8-22:39
 */
/*
 * @PackageName:com.lovvyang.dao.impl
 * @ClassName:UserDaoImpl
 * @Description
 * @author lovvyang
 * @date 2020/6/8/22:39
 **/

public class UserDaoImpl implements UserDao {

    JdbcTemplate jdbcTemplate =new JdbcTemplate(JDBCUtils.getDataSource());

/*
* 登录方法
* */
    @Override
    public User LoginUser(User loginUser) {

        try {
            String sql ="select username,password from user where username=? and password =? ";
            User user = jdbcTemplate.queryForObject(sql,
                    new BeanPropertyRowMapper<>(User.class),
                    loginUser.getUsername(),
                    loginUser.getPassword());
            return user;
        } catch (DataAccessException e) {
            e.printStackTrace();
            return null;
        }
    }
}
